/** Admin Panel*/
package edu.gatech.gui;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

import edu.gatech.presenters.AdminPresenter;
import edu.gatech.userclasses.SysAdmin;

/**
 * @author Courtney
 * @version 2.0
 */
public class AdminPanel {
	/**
	 * username entry field
	 */
	private static JTextField txtUsername = new JTextField();

/**
 * password entry field 
 */
	private static JTextField txtPassword = new JTextField();

/**
 * Panel
 */
	private static JPanel panel = new JPanel();

/**
 * radio Button for patient
 */
	private static JRadioButton radioButton = new JRadioButton();

/**
 * radio Button for nurse
 */
	private static JRadioButton radioButton_1 = new JRadioButton();

/**
 * radio Button for doctor
 */
	private static JRadioButton radioButton_2 = new JRadioButton();

/**
 * radio Button for admin
 */
	private static JRadioButton radioButton_3 = new JRadioButton();

/**
 * Create user Button
 */
	private static JButton btnCreateUser = new JButton();

/**
 * enter username text field
 */
	private static JTextField textField = new JTextField();

/**
 * Search Button
 */
	private static JButton button = new JButton();

/**
 * Search query entry field
 */
	private static JTextField textField_1 = new JTextField();

/**
 * Delete user Button
 */
	private static JButton btnDeleteUser = new JButton();

/**
 * Suspend Account Button
 */
	private static JButton btnSuspend = new JButton();

/**
 * Unsuspend Account Button
 */
	private static JButton btnUnsuspend = new JButton();
	
	/**
	 * width of Panel
	 */
	private static final int WIDTH = 600;
	
	/**
	 * height of Panel
	 */
	private static final int HEIGHT = 480;

	/**
	 * size of font
	 */
	private static final int FONT_SIZE = 10;
	
	/**
	 * x of username text field
	 */
	private static final int TXTUSER_X = 142;

	/**
	 * y of username text field
	 */
	private static final int TXTUSER_Y = 134;

	/**
	 * width of username text field
	 */
	private static final int TXTUSER_WIDTH = 126;

	/**
	 * height of username text field
	 */
	private static final int TXTUSER_HEIGHT = 21;

	/**
	 * number of columns of username text field
	 */
	private static final int TXTUSER_COLUMNS = 15;

	/**
	 * x of password text field
	 */
	private static final int TXTPASS_X = 303;

	/**
	 * y of password text field
	 */
	private static final int TXTPASS_Y = 134;

	/**
	 * width of password text field
	 */
	private static final int TXTPASS_WIDTH = 126;

	/**
	 * height of password text field
	 */
	private static final int TXTPASS_HEIGHT = 21;

	/**
	 * number of columns of password text field
	 */
	private static final int TXTPASS_COLUMNS = 15;

	/**
	 * x of Panel
	 */
	private static final int PANEL_X = 123;

	/**
	 * y of Panel
	 */
	private static final int PANEL_Y = 165;

	/**
	 * width of Panel
	 */
	private static final int PANEL_WIDTH = 327;

	/**
	 * height of Panel
	 */
	private static final int PANEL_HEIGHT = 33;

	/**
	 * x of create user Button
	 */
	private static final int BUTTON_CREATE_X = 234;

	/**
	 * y of create user Button
	 */
	private static final int BUTTON_CREATE_Y = 209;

	/**
	 * width of create user Button
	 */
	private static final int BUTTON_CREATE_WIDTH = 106;

	/**
	 * height of create user Button
	 */
	private static final int BUTTON_CREATE_HEIGHT = 23;

	/**
	 * x of text field
	 */
	private static final int TXT_X = 174;

	/**
	 * y of text field
	 */
	private static final int TXT_Y = 289;

	/**
	 * width of text field
	 */
	private static final int TXT_WIDTH = 227;

	/**
	 * height of text field
	 */
	private static final int TXT_HEIGHT = 20;

	/**
	 * number of columns of text field
	 */
	private static final int TXT_COLUMNS = 15;

	/**
	 * x of Button
	 */
	private static final int BUTTON_X = 499;

	/**
	 * y of Button
	 */
	private static final int BUTTON_Y = 11;

	/**
	 * width of Button
	 */
	private static final int BUTTON_WIDTH = 75;

	/**
	 * height of Button
	 */
	private static final int BUTTON_HEIGHT = 23;

	/**
	 * x of text field
	 */
	private static final int TXTONE_X = 392;

	/**
	 * y of text field
	 */
	private static final int TXTONE_Y = 12;

	/**
	 * width of text field
	 */
	private static final int TXTONE_WIDTH = 105;

	/**
	 * height of text field
	 */
	private static final int TXTONE_HEIGHT = 20;

	/**
	 * number of columns of text field 1
	 */
	private static final int TXTONE_COLUMNS = 10;

	/**
	 * x of delete user Button
	 */
	private static final int BUTTON_DELETE_X = 146;

	/**
	 * y of delete user Button
	 */
	private static final int BUTTON_DELETE_Y = 320;

	/**
	 * width of delete user Button
	 */
	private static final int BUTTON_DELETE_WIDTH = 89;

	/**
	 * height of delete user Button
	 */
	private static final int BUTTON_DELETE_HEIGHT = 23;

	/**
	 * x of suspend user Button
	 */
	private static final int BUTTON_SUSPEND_X = 244;

	/**
	 * y of suspend user Button
	 */
	private static final int BUTTON_SUSPEND_Y = 320;

	/**
	 * width of suspend user Button
	 */
	private static final int BUTTON_SUSPEND_WIDTH = 89;

	/**
	 * height of suspend user Button
	 */
	private static final int BUTTON_SUSPEND_HEIGHT = 23;

	/**
	 * x of unsuspend user Button
	 */
	private static final int BUTTON_UNSUSPEND_X = 344;

	/**
	 * y of unsuspend user Button
	 */
	private static final int BUTTON_UNSUSPEND_Y = 320;

	/**
	 * width of unsuspend user Button
	 */
	private static final int BUTTON_UNSUSPEND_WIDTH = 89;

	/**
	 * height of unsuspend user Button
	 */
	private static final int BUTTON_UNSUSPEND_HEIGHT = 23;
	
	private static SysAdmin currentAdmin;
	
	private static ButtonGroup group;

	/**
	 * 
	 * @param args
	 */
	public AdminPanel(SysAdmin curAdmin){
		currentAdmin = curAdmin;
		final JFrame admin = new JFrame("Admin Panel");
		admin.getContentPane().setFont(new Font("Arial", Font.PLAIN, 10));

		admin.setSize(WIDTH, HEIGHT);
		admin.getContentPane().setLayout(null);
		
		txtUsername = new JTextField();
		txtUsername.setFont(new Font("Arial", Font.PLAIN, FONT_SIZE));
		txtUsername.setBounds(231, 117, 180, 21);
		admin.getContentPane().add(txtUsername);
		txtUsername.setColumns(TXTUSER_COLUMNS);
		
		txtPassword = new JTextField();
		txtPassword.setFont(new Font("Arial", Font.PLAIN, FONT_SIZE));
		txtPassword.setBounds(231, 147, 180, 21);
		admin.getContentPane().add(txtPassword);
		txtPassword.setColumns(TXTPASS_COLUMNS);
		
		group = new ButtonGroup();
		
		radioButton = new JRadioButton("Patient", true);
		radioButton.setBounds(165, 175, 59, 21);
		admin.getContentPane().add(radioButton);
		radioButton.setFont(new Font("Arial", Font.PLAIN, FONT_SIZE));
		group.add(radioButton);
		
		radioButton_1 = new JRadioButton("Nurse", false);
		radioButton_1.setBounds(231, 175, 51, 21);
		admin.getContentPane().add(radioButton_1);
		radioButton_1.setFont(new Font("Arial", Font.PLAIN, FONT_SIZE));
		group.add(radioButton_1);
		
		radioButton_2 = new JRadioButton("Doctor", false);
		radioButton_2.setBounds(291, 175, 57, 21);
		admin.getContentPane().add(radioButton_2);
		radioButton_2.setFont(new Font("Arial", Font.PLAIN, FONT_SIZE));
		group.add(radioButton_2);
		
		radioButton_3 = new JRadioButton("Admin", false);
		radioButton_3.setBounds(354, 175, 57, 21);
		admin.getContentPane().add(radioButton_3);
		radioButton_3.setFont(new Font("Arial", Font.PLAIN, FONT_SIZE));
		group.add(radioButton_3);
		
		btnCreateUser = new JButton("Create User");
		btnCreateUser.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int buttonSelected = 0;
				if(radioButton_1.isSelected()){
					buttonSelected = 1;
				}
				else if(radioButton_2.isSelected()){
					buttonSelected = 2;
				}
				else if(radioButton_3.isSelected()){
					buttonSelected = 3;
				}
				AdminPresenter presenter = new AdminPresenter(currentAdmin);
				presenter.createUser(txtUsername.getText(), txtPassword.getText(), buttonSelected);
				
			}
		});
		btnCreateUser.setFont(new Font("Arial", Font.PLAIN, FONT_SIZE));
		btnCreateUser.setBounds(165, 203, 
								117, 23);
		admin.getContentPane().add(btnCreateUser);
		
		textField = new JTextField();
		textField.setFont(new Font("Arial", Font.PLAIN, FONT_SIZE));
		textField.setColumns(TXT_COLUMNS);
		textField.setBounds(178, 269, 253, 20);
		admin.getContentPane().add(textField);
		
		btnDeleteUser = new JButton("Delete User");
		btnDeleteUser.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				AdminPresenter presenter = new AdminPresenter(currentAdmin);
				presenter.deleteUser(textField.getText());
			}
		});
		btnDeleteUser.setFont(new Font("Arial", Font.PLAIN, FONT_SIZE));
		btnDeleteUser.setBounds(144, 300, 
								BUTTON_DELETE_WIDTH, BUTTON_DELETE_HEIGHT);
		admin.getContentPane().add(btnDeleteUser);
		
		btnSuspend = new JButton("Suspend");
		btnSuspend.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				AdminPresenter presenter = new AdminPresenter(currentAdmin);
				presenter.suspend(textField.getText());
			}
		});
		btnSuspend.setFont(new Font("Arial", Font.PLAIN, FONT_SIZE));
		btnSuspend.setBounds(242, 300, 
							BUTTON_SUSPEND_WIDTH, BUTTON_SUSPEND_HEIGHT);
		admin.getContentPane().add(btnSuspend);
		
		btnUnsuspend = new JButton("Unsuspend");
		btnUnsuspend.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				AdminPresenter presenter = new AdminPresenter(currentAdmin);
				presenter.unSuspend(textField.getText());
			}
		});
		btnUnsuspend.setFont(new Font("Arial", Font.PLAIN, FONT_SIZE));
		btnUnsuspend.setBounds(342, 300, 
								BUTTON_UNSUSPEND_WIDTH, BUTTON_UNSUSPEND_HEIGHT);
		admin.getContentPane().add(btnUnsuspend);
		
		JLabel lblUser = new JLabel("User:");
		lblUser.setFont(new Font("Arial", Font.PLAIN, 10));
		lblUser.setBounds(144, 271, 46, 14);
		admin.getContentPane().add(lblUser);
		
		JPanel panel = new JPanel();
		panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		panel.setBounds(386, 11, 188, 34);
		admin.getContentPane().add(panel);
		
		textField_1 = new JTextField();
		textField_1.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	        	  textField_1.setText(""); 
	          } 
	     }); 
		panel.add(textField_1);
		textField_1.setText("Patient Name");
		textField_1.setFont(new Font("Arial", Font.PLAIN, FONT_SIZE));
		textField_1.setColumns(TXTONE_COLUMNS);
		
		button = new JButton("Search");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
					AdminPresenter presenter = new AdminPresenter(currentAdmin);
					presenter.search(textField_1.getText());
			}
		});
		panel.add(button);
		button.setFont(new Font("Arial", Font.PLAIN, FONT_SIZE));
		
		JPanel panel_2 = new JPanel();
		panel_2.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Actions", TitledBorder.LEADING, TitledBorder.TOP, null, UIManager.getColor("Button.darkShadow")));
		panel_2.setBounds(126, 250, 318, 84);
		admin.getContentPane().add(panel_2);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.setFont(new Font("Arial", Font.PLAIN, 10));
		btnCancel.setBounds(291, 203, 120, 23);
		admin.getContentPane().add(btnCancel);
		
		JLabel lblUsername = new JLabel("Username:");
		lblUsername.setFont(new Font("Arial", Font.PLAIN, 10));
		lblUsername.setBounds(174, 120, 59, 14);
		admin.getContentPane().add(lblUsername);
		
		JLabel lblPassword = new JLabel("Password:");
		lblPassword.setFont(new Font("Arial", Font.PLAIN, 10));
		lblPassword.setBounds(175, 150, 46, 14);
		admin.getContentPane().add(lblPassword);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Create User", TitledBorder.LEADING, TitledBorder.TOP, null, UIManager.getColor("Button.darkShadow")));
		panel_1.setBounds(144, 96, 287, 143);
		admin.getContentPane().add(panel_1);
		admin.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		admin.setSize(600,480);
		admin.setTitle("System Admin Panel");
		admin.setLocationRelativeTo(null);  
		admin.setVisible(true);
	}
	
	/**
	 * @return empty string
	 */
	public String toString(){
		return "";
	}
}
